Page({
  data: {
    student: { name: "", studentId: "", major: "" },
    transcript: { semester: "", gpa: 0, totalCredits: 0, courses: [] },
  },

  onLoad() {
    this.loadData();
  },

  onShow() {
    this.loadData();
  },

  loadData() {
    const local = require("../../../../utils/local");
    const t = local.getTranscript();
    const app = getApp();
    const raw = app.globalData.userInfo || wx.getStorageSync("userInfo") || {};
    const student = {
      name: raw.realName || raw.name || "",
      studentId: raw.username || raw.studentId || "",
      major: (raw.profile && raw.profile.major) || "",
    };
    if (t) {
      this.setData({ student, transcript: t });
    }
  },

  edit() {
    const local = require("../../../../utils/local");
    const t = local.getTranscript();
    if (!t) return;
    wx.navigateTo({
      url: `/pages/student/transcript/edit/edit?data=${encodeURIComponent(
        JSON.stringify(t)
      )}`,
    });
  },

  revoke() {
    wx.showModal({
      title: "确认撤回",
      content: "撤回后将删除当前成绩单，是否继续？",
      success: (r) => {
        if (r.confirm) {
          const local = require("../../../../utils/local");
          const result = local.removeTranscript();
          if (result.success) {
            wx.showToast({ title: "已撤回", icon: "success" });
            setTimeout(() => wx.navigateBack(), 500);
          }
        }
      },
    });
  },
});









